﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading;
using System.Net;

using MailEngine;
using Utility;
using Entity;

namespace MySparrowConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            string _command = null;
            //string[] sssss = Utility.DnsMx.GetMXRecords("163.com");
            //IPAddress[] ips = Dns.GetHostAddresses("netease.com"); 
            UserAccount _ua = new UserAccount();
            /*****************************EWS 2007 SP1**************************************/
            _ua.MailDisplayName = "Accenture EWS";
            _ua.MailAddress = "volker.zhang@accenture.com";
            _ua.EWSDomain = "dir";
            _ua.MailPassword = "&UJM6yhn";//shift 7 不shift 6
            _ua.ServiceType = ServiceType.EWS;

            IMailEngine ewsIM = new MailEngine.EwsEngine();
            ewsIM.Connection(_ua);//建立Exchange Web Service
            //List<MailFolder> _folderList = ewsIM.GetFolderList(_ua);//获取全部目录列表
            int _fullCount = ewsIM.GetFullMailCount(_ua);
            int _unreadCount = ewsIM.GetUnreadMailCount(_ua);
            //string _inboxFolderID = "AAMkADg4MjY4N2UzLTFiZjgtNGZkZi04Y2Q4LWY5ZjNkMTVkODJkYQAuAAAAAAAhQqzZ0u8yR4PNFtu4tjSbAQDk1ySn2QaFRpozopTAyIUuABJ/tqe9AAA=";
            //string _trashFolderID = "AAMkADg4MjY4N2UzLTFiZjgtNGZkZi04Y2Q4LWY5ZjNkMTVkODJkYQAuAAAAAAAhQqzZ0u8yR4PNFtu4tjSbAQDk1ySn2QaFRpozopTAyIUuABJ/tqfAAAA=";
            //List<MailFolder> _subList = ewsIM.GetFolderList(_ua, MailFolderType.Other, _inboxFolderID);//获取特定目录的子文件夹列表
            //MailList _fullList = ewsIM.GetMailList(_ua, _inboxFolderID, 10, 0, true, false);//获取全量邮件列表
            //MailList _fullList = ewsIM.GetMailList(_ua, _inboxFolderID, 10, 0, false, false);//获取增量邮件列表
            //string _mailCounts = ewsIM.GetMailList(_ua, null, 10, 0, true, true).TotalCount.ToString();//获取全部邮件数量
            //ewsIM.EmptyFolder(_ua, _trashFolderID);//清空废件箱，只支持ews 2010 sp1以上版本服务器
            //Mail ffff = im.CreateMail(null,null,null,null,"fffffff",null,null);
            //List<ContactNameCard> ffdd = new List<ContactNameCard>();
            //ContactNameCard aaa = new ContactNameCard();
            //Mail mm = new Mail();
            //mm.AttachmentFileList.Add(
            //aaa.ContactName = "volkerzht";
            //aaa.MailAddress = "volker_zht@163.com";
            //ffdd.Add(aaa);
            //mm.Subject = "测试邮件xxx";
            //mm.TextContent = "就为了测试";
            //mm.To = ffdd;

            //string testFolderID = "";
            //string testMailID = "AAMkADg4MjY4N2UzLTFiZjgtNGZkZi04Y2Q4LWY5ZjNkMTVkODJkYQBGAAAAAAAhQqzZ0u8yR4PNFtu4tjSbBwDk1ySn2QaFRpozopTAyIUuABJ/tqe9AADy2jkX2UPESZPtUINJIbczAAAJnVc5AAA=";
            //ewsIM.CreateFolder(ua, "testFolder", inboxFolderID);//创建文件夹
            //ewsIM.DeleteFolder(ua, testFolderID, DeleteModes.HardDelete);//删除文件夹
            //ewsIM.RenameFolder(ua, testFolderID, "testFolder3334444");//重命名文件夹
            
            //MailList _list = ewsIM.GetMailList(_ua, trashFolderID, 10, 0, true);//获取邮件列表，获取完应该在服务器修改isRead状态为已读
            //MailList _list2 = ewsIM.GetMailList(_ua, inboxFolderID, 10, 0, true);//获取邮件列表
            //ewsIM.SaveMail(_ua, mm);//保存邮件到草稿
            //ewsIM.SendMail(_ua, mm);//发送邮件并保存到已发送
            //ewsIM.DeleteMail(_ua, testMailID, DeleteModes.MoveToDeletedItems);
            //ewsIM.MoveMail(_ua, testMailID, inboxFolderID);//移动邮件
            //ewsIM.CopyMail(_ua, testMailID, trashFolderID);//复制邮件
            /*********************************POP*******************************************/
            //_ua.MailDisplayName = "163 POP";
            //_ua.MailAddress = "volker_zht@163.com";
            //_ua.MailPassword = "VolkerZhang1982";
            //_ua.ReciveServer = "pop.163.com";
            //_ua.ReciveServerPort = 110;
            //_ua.ServiceType = ServiceType.POP;

            //IMailEngine popIM = new MailEngine.PopEngine();
            //popIM.Connection(_ua);//建立POP Service链接
            //MailList _popML = popIM.GetMailList(_ua, null, 0, 0, true);//获取邮件列表
            /********************************IMAP*******************************************/
            //_ua.MailDisplayName = "163 IMAP";
            //_ua.MailAddress = "volker_zht@163.com";
            //_ua.MailPassword = "VolkerZhang1982";
            //_ua.ReciveServer = "imap.163.com";
            //_ua.ReciveServerPort = 143;
            //_ua.ServiceType = ServiceType.IMAP;
            /////////////////////////////////////////////////////////////////////
            //_ua.MailDisplayName = "GMail IMAP";
            //_ua.MailAddress = "volkerzht@gmail.com";
            //_ua.MailPassword = "VolkerZhang1982";
            //_ua.ReciveServer = "pop.gmail.com";
            //_ua.ReciveServerPort = 995;
            //_ua.ServiceType = ServiceType.POP;
            //_ua.IsSSL = true;

            //IMailEngine imapIM = new MailEngine.ImapEngine();
            //imapIM.Connection(_ua);
            //List<MailFolder> _folderList = imapIM.GetFolderList(_ua, MailFolderType.MsgRoot, null);//目前只支持根目录，163没有子目录，Google待定
            //string _folderID = "INBOX";
            //MailList _mailList = imapIM.GetMailList(_ua, _folderID, 0, 0, true);
            /*******************************************************************************/ 

            while (_command != ":q")
            {
                Console.Write("user_account$>");
                _command = Console.ReadLine();

                switch (_command)
                {
                    case ":q":
                        break;
                    case ":c":
                        
                        break;
                    default:
                        Console.WriteLine("error");
                        break;
                }
            }
        }

        private static void getMail()
        {
            
        }
        //private static void EditMode()
        //{
        //    char _inputChar;
        //    StringBuilder sb = new StringBuilder();
        //    Console.Write("user_account#>");
        //    while (true)
        //    {
        //        _inputChar = Console.ReadKey(true).KeyChar;
        //        if (_inputChar == 27)
        //        {
        //            Console.Write("EXIT Edit Mode\r\n");
        //            break;
        //        }
        //        else if (_inputChar == 13)
        //        {
        //            Console.Write("\n");
        //            Console.Write("user_account#>");
        //            sb.Append("\r\n");
        //        }
        //        else
        //        {
        //            Console.Write(_inputChar);
        //            sb.Append(_inputChar);
        //        }
        //    }
        //}

        static void test()
        {
            for (int i = 0; i < 100; i++)
            {
                Console.Write(".");
            }
        }

    }
}
